﻿
layui.define(function (exports) {
    exports("GSLayui",
        {
            layuiTablePageList: function (id, url, cols, where) {
                var tableOption = {
                    elem: "#" + id,
                    toolbar: '#toolbar',
                    defaultToolbar: [], //在右边不显示过滤字段、导出excel、打印功能
                    cellMinWidth: 80,  //全局定义常规单元格的最小宽度
                    page: true,
                    contentType: "application/json",
                    where: where,

                    id: id,
                    method: 'post',
                    headers: { 'Authorization': 'Bearer ' + getCookie('Token') },
                    response: {
                        StatusCode: 200,
                    },
                    parseData: function (res) {
                        return {
                            "code": res.Data.code == 200 ? 0 : 1,
                            "msg": res.Data.msg,
                            "count": res.Data.count,
                            "data": res.Data.data
                        }
                    },
                    limits: [10, 20, 50, 100],
                    loading: true,
                    done: function (d) {
                    },
                    url: url,
                    cols: [
                        cols
                    ]
                };
                return tableOption;

            }, layuiTable: function (id, url, cols, where) {

                var tableOption = {
                    elem: "#" + id,
                    toolbar: '#toolbar',
                    defaultToolbar: [], //在右边不显示过滤字段、导出excel、打印功能
                    cellMinWidth: 80,  //全局定义常规单元格的最小宽度
                    page: true,
                    id: id,
                    contentType: "application/json",
                    headers: { 'Authorization': 'Bearer ' + getCookie('Token') },
                    where: where,
                    method: 'post',

                    response: {
                        statusCode: 200,//规定成功的状态码，默认：0
                    },
                    limits: [10, 20, 50, 100],
                    loading: true,
                    done: function (d) {
                    },
                    url: url,
                    cols: [
                        cols
                    ]
                };
                return tableOption;

            }, apiTable: function (id, url, cols, where) {

                var tableOption = {
                    elem: "#" + id,
                    toolbar: '#toolbar',
                    defaultToolbar: [], //在右边不显示过滤字段、导出excel、打印功能
                    cellMinWidth: 80,  //全局定义常规单元格的最小宽度
                    page: true,
                    id: id,
                    contentType: "application/json",
                    headers: { 'Authorization': 'Bearer ' + getCookie('Token') },
                    where: where,
                    method: 'post',

                    response: {
                        statusCode: 200,//规定成功的状态码，默认：0
                    },
                    parseData: function (res) {

                        return res.Data;
                       
                    },
                    limits: [10, 20, 50, 100],
                    loading: true,
                    done: function (d) {
                    },
                    url: url,
                    cols: [
                        cols
                    ]
                };
                return tableOption;

            }, uploadFile: function (id, listid, ftype, fexts, size, fileName) {
                fileName = fileName ? fileName : '';
                if (fexts == "" || fexts == null || fexts == undefined) {
                    fexts = "pdf|doc|docx|png|ppt|pptx";
                }

                var uploadOption = {
                    elem: id//'#sbsList'
                    , elemList: $('#' + listid) //$('#sqhTbList') //列表元素对象
                    , acceptMime: "image/png,application/pdf,application/msword"
                    , exts: fexts
                    , url: '/FileApi/Enclosure', size: size || '1024*10'
                    , multiple: !ftype
                    , bindAction: ''
                    , done: function (res, index, upload) {


                        var strmy = res.value.value + "&" + this.files[index].name + "^";
                        var html = $(['<tr id="shenupload-' + index + '">'
                            , '<td>' + this.files[index].name + '</td>'
                            , '<td>' + new Date().toLocaleDateString() + '</td>'
                            , '<td> <a data-type="' + fileName + '" data-id="' + strmy + '"  class="del">删除</a> </td>'

                            , '</tr>'].join(''));

                        var that = this;
                        delete this.files[index]; //删除文件队列已经上传成功的文件
                        that.elemList.append(html);


                    }
                    , choose: function (obj) {
                        console.log(obj)
                        var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列

                    }
                    , error: function (data) {
                        debugger;
                    }
                    , progress: function (n, elem, e, index) { //注意：index 参数为 layui 2.6.6 新增
                        // element.progress('progress-demo-' + index, n + '%'); //执行进度条。n 即为返回的进度百分比
                    }
                }
                return uploadOption
            }, uploadImageOne: function (id, listid, fexts, size, fileName) {
                if (fexts == "" || fexts == null || fexts == undefined) {
                    fexts = "jpg|png|webp|bmp|jpeg|gif|ico";
                }
                ;
                var uploadOption = {
                    elem: id//'#sbsList'
                    , elemList: $('#' + listid) //$('#sqhTbList') //列表元素对象
                    , acceptMime: "image/*"
                    , exts: fexts
                    , url: '/FileApi/Enclosure', size: size || '1024*10'
                    , multiple: false
                    , bindAction: ''
                    , done: function (res, index, upload) {
                        //debugger
                        var strmy = res.value.value + "&" + this.files[index].name + "^";
                        var html = '<input data-type="' + fileName + '"class="del" type="hidden" value="' + strmy + '"/>';

                        var that = this;
                        delete this.files[index]; //删除文件队列已经上传成功的文件

                        that.elemList.html(html + '<img class="layui-upload-img image_src" style="pointer-events: none; width: 100%; height: 198px;" src="' + res.value.value + '">')


                    }
                    , choose: function (obj) {
                        console.log(obj)

                        var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列

                    }
                    , error: function (data) {
                        debugger;
                    }
                    , progress: function (n, elem, e, index) { //注意：index 参数为 layui 2.6.6 新增

                    }
                }
                return uploadOption

            },
            uploadImages: function (id, listid, ftype, fexts) {
                if (fexts == "" || fexts == null || fexts == undefined) {
                    fexts = "pdf|doc|docx|png|ppt|pptx";
                }
                //debugger;
                var uploadOption = {
                    elem: id//'#sbsList'
                    , elemList: $('#' + listid) //$('#sqhTbList') //列表元素对象
                    , acceptMime: "image/png,application/pdf,application/msword"
                    , exts: fexts
                    , url: '/FileApi/Enclosure', size: '1024*10'
                    , multiple: true
                    , bindAction: ''
                    , done: function (res, index, upload) {
                        if (ftype == 'image') {// 上传自定义图片类型
                            this.elemList.html('<img class="layui-upload-img image_src" style="pointer-events: none; width: 100%; height: 80px;" src="' + res.value.value + '">')
                        }

                    }
                    , choose: function (obj) {
                        console.log(obj)
                        debugger;
                        var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列

                    }
                    , error: function (data) {
                        debugger;
                    }
                    , progress: function (n, elem, e, index) { //注意：index 参数为 layui 2.6.6 新增
                        // element.progress('progress-demo-' + index, n + '%'); //执行进度条。n 即为返回的进度百分比
                    }
                }
                return uploadOption
            }
        });
});